package com.droowa.model.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.droowa.domain.CompletePC;
import com.droowa.domain.CompletePCResult;
import com.droowa.domain.FirstCategory;
import com.droowa.domain.Product;
import com.droowa.model.dao.ProductManagementDAO;
import com.droowa.util.PagingBeanProduct;

@Service
public class ProductManagementServiceImpl implements ProductManagementService {

	@Autowired
	private ProductManagementDAO dao;

	@Override
	public void registerFirstCategory(FirstCategory firstCategory)
			throws SQLException {
		dao.insertFirstCategory(firstCategory);
	}

	@Override
	public void modifyFirstCategoryById(FirstCategory firstCategory)
			throws SQLException {
		dao.updateFirstCategoryById(firstCategory);
	}
	
	@Override
	public void modifyProductCategoryName(Product product)
			throws SQLException {
		dao.updateProductCategoryName(product);
	}

	@Override
	public void removeFirstCategoryById(String id) throws SQLException {
		dao.deleteFirstCategoryById(id);
	}
	
	@Override
	public List<FirstCategory> getCategoryList() throws SQLException {
		return dao.selectCategoryList();
	}
	
	@Override
	public List<FirstCategory> getFixedCategoryList() throws SQLException {
		return dao.selectFixedCategoryList();
	}
	
	@Override
	public List<FirstCategory> getUnFixedCategoryList() throws SQLException {
		return dao.selectUnFixedCategoryList();
	}

	@Override
	public FirstCategory getFirstCategoryById(String categoryId) throws SQLException {
		return dao.selectFirstCategoryById(categoryId);
	}

	@Override
	public void registerProduct(Product product) throws SQLException {
		dao.insertProduct(product);
	}

	@Override
	public void modifyProduct(Product product) throws SQLException {
		dao.updateProduct(product);
	}

	@Override
	public void removeProductById(String id) throws SQLException {
		dao.deleteProductById(id);
	}

	@Override
	public List<Product> getProductList() throws SQLException {
		return dao.selectProductList();
	}

	@Override
	public List<Product> getRemovedProductList() throws SQLException {
		return dao.selectRemovedProductList();
	}
	
	@Override
	public Map getProductListPaging(int page) throws SQLException {
		List<Product> list = dao.selectProductListPaging(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountPL(),page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public Map getRemovedProductListPaging(int page) throws SQLException {
		List<Product> list = dao.selectRemovedProductListPaging(page);
		PagingBeanProduct pb = new 	PagingBeanProduct(dao.selectRowCountRPL(),page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public Product getProductById(String id) throws SQLException {
		return dao.selectProductById(id);
	}

	@Override
	public Map getProductByName(String name, int page) throws SQLException {
		List<Product> list = dao.selectProductByName(name, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountPN(name),page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}
	@Override
	public List<Product> getProductByBrand(String brand) throws SQLException {
		return dao.selectProductByBrand(brand);
	}
	@Override
	public Map getProductByBrandPaging(String brand, int page) throws SQLException {
		List<Product> list = dao.selectProductByBrandPaging(brand, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountB(brand),page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public Map getProductByModelNo(String modelNo, int page) throws SQLException {
		List<Product> list = dao.selectProductByModelNo(modelNo, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountM(modelNo),page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public Map getProductByPriceRange(int sPrice, int ePrice, int page)
			throws SQLException {
		List<Product> list = dao.selectProductByPriceRange(sPrice, ePrice, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountPR(sPrice, ePrice),page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public Map getRProductByName(String name, int page) throws SQLException {
		List<Product> list = dao.selectRProductByName(name, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountRPN(name),page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public List<Product> getRProductByBrand(String brand) throws SQLException {
		return dao.selectRProductByBrand(brand);
	}
	@Override
	public Map getRProductByBrandPaging(String brand, int page) throws SQLException {
		List<Product> list = dao.selectRProductByBrandPaging(brand, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountRB(brand),page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}
	@Override
	public Map getRProductByModelNo(String modelNo, int page) throws SQLException {
		List<Product> list = dao.selectRProductByModelNo(modelNo, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountRM(modelNo),page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public Map getRProductByPriceRange(int sPrice, int ePrice, int page)
			throws SQLException {
		List<Product> list = dao.selectRProductByPriceRange(sPrice, ePrice, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountRPR(sPrice, ePrice),page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public void modifyDelToTrue(Product product) throws SQLException {
		dao.updateDeltoTrue(product);
	}

	@Override
	public void modifyDelToFalse(Product product) throws SQLException {
		dao.updateDeltoFalse(product);
	}

	@Override
	public Map getInventoryList(int page) throws SQLException {
		List<Product> list = dao.selectInventoryList(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountPL(),page);
		HashMap map = new HashMap();
		map.put("inventory_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public void modifySafeInventory(Product product) throws SQLException {
		dao.updateSafeInventory(product);
	}

	@Override
	public Map getProductByCategoryName(String categoryName, int page) throws SQLException{
		List<Product> list = dao.selectProductByCategoryName(categoryName, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountCN(categoryName), page);
		HashMap map = new HashMap();
		map.put("product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public Map getRProductByCategoryName(String categoryName, int page) throws SQLException{
		List<Product> list = dao.selectRProductByCategoryName(categoryName, page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountRCN(categoryName), page);
		HashMap map = new HashMap();
		map.put("removed_product_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public void registerCompletePC(CompletePC completePC) throws SQLException {
		dao.insertCompletePC(completePC);
	}

	@Override
	public List getCompletePCList() throws SQLException {
		return dao.selectCompletePCList();
	}
	
	@Override
	public Map getCompletePCListPaging(int page) throws SQLException {
		List<CompletePC> list = dao.selectCompletePCListPaging(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountCPL(),page);
		HashMap map = new HashMap();
		map.put("computer_list", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public List<CompletePCResult> getCompletePCByCPUBrand(String cpu,
			String brand) throws SQLException {
		return dao.selectCompletePCByCPUBrand(cpu, brand);
	}

	@Override
	public Map getCompleteEventPaging(int page) throws SQLException {
		List<CompletePC> list = dao.selectCompleteEventPaging(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountEPL(),page);
		HashMap map = new HashMap();
		map.put("event_list", list);
		map.put("paging", pb);
		return map;
	}
	@Override
	public List getCompleteNameById(String id) throws SQLException {
		return dao.selectCompleteNameById(id);
	}
	
	@Override
	public List getCompletePC(String completeId) throws SQLException {
		return dao.selectCompletePC(completeId);
	}
	
	@Override
	public List<CompletePCResult> getCompletePCByPrice(int sPrice, int ePrice)
			throws SQLException {
		return dao.selectCompletePCByPrice(sPrice, ePrice);
	}

//	@Override
//	public List<CompletePCResult> getCompletePCByCPU(String cpu)	throws SQLException {
//		return dao.selectCompletePCByCPU(cpu);
//	}
	@Override
	public CompletePC getCompleteDomain(String completeId) throws SQLException {
		return dao.selectCompleteDomain(completeId);
	}

	@Override
	public Map<String, String> getCompletePCById(String completeId)
			throws SQLException {
		return dao.selectCompletePCById(completeId);
	}

	@Override
	public void modifyCompletePC(CompletePC completePC) throws SQLException {
		dao.updateCompletePC(completePC);
		
	}
	@Override
	public void removeCompletePCById(String completeId) throws SQLException {
		dao.deleteCompletePCById(completeId);
		
	}

	@Override
	public void modifyEventToTrue(CompletePC completePC) throws SQLException {
		dao.updateEventToTrue(completePC);
		
	}
	
	@Override
	public void modifyEventToFalse(CompletePC completePC) throws SQLException {
		dao.updateEventToFalse(completePC);
		
	}

	@Override
	public List<CompletePC> getEventList() throws SQLException {
		return dao.selectEventList();
	}

	@Override
	public Map getCompletePCByLow(int page) throws SQLException {
		List<CompletePCResult> list = dao.selectCompletePCByLow(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountLP(),page);
		HashMap map = new HashMap();
		map.put("lowList", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public Map getCompletePCByHigh(int page) throws SQLException {
		List<CompletePCResult> list = dao.selectCompletePCByHigh(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountLP(),page);
		HashMap map = new HashMap();
		map.put("highList", list);
		map.put("paging", pb);
		return map;
	}

	@Override
	public Map getCompletePCByIdPrice(String completeId) {
		return dao.selectCompletePCByIdPrice(completeId);
	}	
	
	@Override
	public Map getCompletePCByCPUPaging(int page)	throws SQLException {
		List<CompletePCResult> list = dao.selectCompletePCByCPUPaging(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountLP(),page);
		HashMap map = new HashMap();
		map.put("cpuList", list);
		map.put("paging", pb);
		return map;
	}
	
	@Override
	public Map getCompletePCByGRAPHICPaging(int page)	throws SQLException {
		List<CompletePCResult> list = dao.selectCompletePCByGRAPHICPaging(page);
		PagingBeanProduct pb = new PagingBeanProduct(dao.selectRowCountLP(),page);
		HashMap map = new HashMap();
		map.put("graphicList", list);
		map.put("paging", pb);
		return map;
	}

	//완제품 PC 판매량 ++
	@Override
	public void modifyCompletePCCnt(String completeId, int cnt) {
		dao.updateCompletePCCnt(completeId, cnt);
	}

	@Override
	public CompletePC getCompletePCByIdBasic(String completeId) {
		return dao.selectCompletePCByIdBasic(completeId);
	}

	@Override
	public void modifyProductQuantity(String id) {
		dao.updateProductQuantity(id);
	}
	
	
	
	

}
